const url = require('url');

const url_object = new url.URL('https://user:pass@sub.example.com:8080/p/a/t/h?query=string#hash'); // WHATWG
// const url_object = url.parse('https://user:pass@sub.example.com:8080/p/a/t/h?query=string#hash'); // Legacy
console.log(url_object);

const myURL = new url.URL('/foo', 'https://example.org/');
// https://example.org/foo
// const myURL = new URL({ toString: () => 'https://example.org/' });